package com.itwlj.controller.admin;

import com.itwlj.dto.SpecValueDTO;
import com.itwlj.dto.SpecValuePageQueryDTO;
import com.itwlj.entity.SpecValue;
import com.itwlj.result.PageResult;
import com.itwlj.result.Result;
import com.itwlj.service.SpecValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 规格值管理
 */
@RestController
@RequestMapping("admin/spec/value")
@Api(tags = "规格值相关接口")
@Slf4j
public class SpecValueController {

    @Autowired
    private SpecValueService specValueService;

    /**
     * 新增规格值
     *
     * @param specValueDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增规格值")
    public Result<String> insert(@RequestBody SpecValueDTO specValueDTO) {
        log.info("新增规格值：{}", specValueDTO);
        specValueService.insert(specValueDTO);
        return Result.success();
    }

    /**
     * 规格值分页查询
     *
     * @param specValuePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("规格值分页查询")
    public Result<PageResult> page(SpecValuePageQueryDTO specValuePageQueryDTO) {
        log.info("规格值分页查询：{}", specValuePageQueryDTO);
        PageResult pageResult = specValueService.pageQuery(specValuePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除规格值
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除规格值")
    public Result<String> delete(@RequestParam List<Long> ids) {
        log.info("删除规格值：{}", ids);
        specValueService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 查询规格值
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询规格值")
    public Result<List<SpecValue>> list() {
        log.info("查询规格值");
        List<SpecValue> specValueList = specValueService.list();
        return Result.success(specValueList);
    }
}
